package com.sky.controller.admin;

import com.sky.constant.ShopStatus;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Slf4j
@Api(tags = "店铺操作相关接口")
public class ShopController {

    @Autowired
    RedisTemplate redisTemplate;

    @PutMapping("/{status}")
    public Result updateStatus(@PathVariable Integer status){
        log.info("修改店铺状态,状态为{}",status);

        ValueOperations opsForValue = redisTemplate.opsForValue();
        opsForValue.set(ShopStatus.SHOP_STATUS,status);
        return Result.success();
    }

    @GetMapping("/status")
    public Result<Integer> getStatus(){
        ValueOperations opsForValue = redisTemplate.opsForValue();
        Integer status = (Integer) opsForValue.get(ShopStatus.SHOP_STATUS);
        return Result.success(status==null?0:status);
    }
}
